//
//  MineHeaderTableViewCell.m
//  StockNet
//
//  Created by 小焘无量 on 2023/1/7.
//

#import "MineHeaderTableViewCell.h"
#import "LoginViewController.h"
#import "NSString+Encrypt.h"
#import <NSString+SHExtension.h>


@interface MineHeaderTableViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *headerImgView;//头像
@property (weak, nonatomic) IBOutlet UILabel *userNameLab;// 用户昵称
@property (weak, nonatomic) IBOutlet UILabel *memberStateLab;// 会员状态
@property (weak, nonatomic) IBOutlet UIButton *openBtn;// 开通按钮

@property (weak, nonatomic) IBOutlet UILabel *noteLab;// 会员简述



@property (weak, nonatomic) IBOutlet UIView *noticeBgView;


@property (weak, nonatomic) IBOutlet UIView *bottomBgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLayout;// 80 10


@end

@implementation MineHeaderTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.noticeBgView.backgroundColor =
    self.bottomBgView.backgroundColor = kRGBA(0x6AA94E, 0.3);
    [self.openBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    self.openBtn.layer.borderColor = kThemeColor.CGColor;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 点击头像登录
- (IBAction)loginAction:(id)sender {
    if (![YTClient shared].isLogin) {
        [[YTClient shared] presentLoginControllerFrom:[NSObject getCurrentViewController] showClose:YES];
    }
}



// 请登录
// 您可以联系管理员上传公司库存资料
// 如果您的会员期限已到期，为了不影响您的正常使用，请及时续费。

- (IBAction)openBtnAction:(UIButton *)sender {
    
//    [self testNetwork];
//
//    return;
    if (![YTClient shared].isLogin) {
        LoginViewController *vc = [[LoginViewController alloc]initWithShowClose:YES];
        [[NSObject getCurrentViewController] yt_presentViewController:vc animated:YES completion:nil];
        return;
    }
    
    if (![YTClient shared].isMember) {
        WeakSelf;
        // 非会员 -> 开通会员
//        [ChosePayTypeView showComplate:^(NSString * _Nonnull payType) {
//            [UIAlertController alertWithController:[NSObject getCurrentViewController] title:nil message:@"请联系销售:13788932357" actionTitles:@[@"取消", @"确定"] actionOne:nil actionTwo:^{
//                [weakSelf callMethod];
//            }];
//        }];
        
        [self callMethod];
        
    }else {
        // 会员 -> 联系客服
        [self callMethod];
    }
}

-(void)setNeedUpdate:(BOOL)needUpdate {
    
//    @property (weak, nonatomic) IBOutlet UIImageView *headerImgView;//头像
//    @property (weak, nonatomic) IBOutlet UILabel *userNameLab;// 用户昵称
//    @property (weak, nonatomic) IBOutlet UILabel *memberStateLab;// 会员状态
//    @property (weak, nonatomic) IBOutlet UIButton *openBtn;// 开通按钮
//
//    @property (weak, nonatomic) IBOutlet UILabel *noteLab;// 会员简述
    
    YTClient *shared = [YTClient shared];
    YTUser *user = shared.user;
    self.bottomBgView.hidden = YES;
    self.bottomLayout.constant = 10;
    
    if (!shared.isLogin) {
        
        self.userNameLab.text = @"请登录";
        self.memberStateLab.text = @"";
        self.openBtn.hidden = YES;
        self.noteLab.text = @"登录成功即可查看部分数据信息";
        self.headerImgView.image = ImageWithName(@"icon_mine_header_1");
        
        return;
    }
    
    if (!shared.isMember) {
        self.userNameLab.text = FormatString(@"用户%@", user.account);
        self.memberStateLab.text = @"您还不是会员";
        self.openBtn.hidden = NO;
        [self.openBtn setTitle:@"立即开通" forState:UIControlStateNormal];
        self.noteLab.text = @"您的会员期限已到期，为了不影响您的正常使用，请及时续费。";
        self.bottomBgView.hidden = NO;
        self.bottomLayout.constant = 80;
        self.headerImgView.image = ImageWithName(@"icon_mine_header_2");
    }else {
        self.userNameLab.text = FormatString(@"尊敬的年费会员%@", user.account);
        self.memberStateLab.text = FormatString(@"会员到期时间：%@", [NSString stringFromTimeStamp:user.member_expires/1000]);
        self.openBtn.hidden = NO;
        [self.openBtn setTitle:@"联系客服" forState:UIControlStateNormal];
        self.noteLab.text = @"您现在可以随意找货，电话直接联系，也可联系客服上传自家库存，也可联系客服投诉虚假现货资源。";
        
        self.headerImgView.image = ImageWithName(@"icon_mine_header_3");
    }
    
}

-(void)callMethod {
    NSString *str = @"telprompt://13788932357";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil];
}

-(void)testNetwork {
    //aes-key
    NSString *key = @"O2BEeIv399qHQNhD6aGW8R8DEj4bqHXm";
    NSString *vi = [key substringFromIndex:16];

    //加密字符串
    NSString *message = @"NvIFO5WGVnlNiPgdiuJ/QRe62JRdjZ+7q7OiOqY6XmJrM8bgT167MO70rW0xu+SyHqn3XkbR9tD741StXBYXdFTR8P5zaWT7Dhw72NiW6EQHKXeOsWx0F7DfIJW9axo1EZfVdjWTb20jMjT+8nI4bRGn+AMraGKT7gBTA4Y5AMKQ1EOmq+2TabL1ZizFuDCqpDfGEwR1wxYdYWGRYScoE87oL4oHwMpDGN43yW1QyfjWAfYB8NtBbFt1UADzRFygXoEdavkRLKBI0MLlffsx1inAxFd8h5qzwPaySGWOsJ852Te2XqnHsN8r0FmyghJigCk335CBxz4yVbpTpN0d/Q6t+CJI/Xw/C7eLAxB/+pXE/i4xRI7YYZ0inW7hrPOQe3Wxdb2UraKJ31CRv5IQogiQdHOo7FL+6T1mQE859ZxCkpR4Dgqk3uLJJ6buFtqHbiGaVwcgiNdFo1JItyiIC7BIRqGb3lI8qbPgKVtejN9E3VIx9BOgYS69QaHXVde/vDNB2lk6Rjkpd+fwYJF47e6Ik/1Devk30n9lV0Kg3GiR43bPJnwDiUrkwg6MQiiB8xQfcvH0Y6J4FaiS5PgQ3Vz8ruV6YqqIOhMZw1gMlrDvW9T8EBLp9d153ebEJQIWwT6RJ7QwV822p52UpgLqLZKgSfE8EiSnSkIkXv55XFGTLgAVVkHF8hpANwnkcMnEz1gxCIl43khD84uX7ZPZJsX/uz7iclZdi20NO5OtBzZzJDUVMn5XPTCGwCMr6Kh3OYyE9JuQClPP+eDwiyxiZeAwahF37VogFfUcz1Np33plzu1RY10/xU7VhphKbHa25SCGGL1Ze7KH2shWOsq/SUTWEfyWg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u4FUEtJZ5x8+CtfzOxEKNNKb99An0S4wvdheiZp1Xcg0r7owtN90/s8M8MwJQEU1YNeB5cq129Allm0cWAmmnqvPQOA0hcp4kjKOWu6+zuXWl6JFJ0O7iLvomYxBm9HJ+zviV5jjtYalr4Hnmxr8Q2JqOhy79y8OF1OU8Cs7O5EJ3CgWxpgBAyi+RDM3LD3gnjdOlJFh8KnNBHAUzaA1EEu3S9JePdjfkmCFffAPHaDXZB6CTnVFw3/Up9LtbY0HeJX36+Ap9KCTPJZ02Z5bT5SAPx7IN1gMCLEquRCaxCqHR8AFvcp3AhVPzAIjLG/C6LlbzXP3xlWGKxVkBlP";
    
//    NSString *test = @"123456";
//    NSString *testDecode = [NSString encryptAESWithPlainText:test key:key];
//    NSString *testResult = [NSString decryptAESWithCipherText:testDecode key:key];
    
    NSString *result = [NSString decryptAESWithCipherText:message key:key];
    
//    NSString *result = [message AES128DecryptWithKey:key iv:vi];
    DLog(@"%@", result);

}

@end
